package com.linzelin.www.po;

import com.linzelin.www.util.Manager;

import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
import java.util.Scanner;
import java.util.Set;

public class Account_manager {
    Properties prop = new Properties();
    //还是用这个来注册账号比较方便
    public void Land(Manager manager) throws Exception {
        Properties prop_find = new Properties();
        prop_find.load(new FileReader("C:\\Users\\啦啦啦\\Desktop\\Manager.txt"));
        Set<String> set = prop_find.stringPropertyNames();
        while(true) {
            for (String s : set) {
                if (s.equals(manager.getUsename())) {
                    if (prop_find.get(s).equals(manager.getPassword())) {
                        System.out.println("正在登入\n=================");
                        Thread.sleep(2000);
                        return;
                    } else {
                        String code;
                        while (!(prop_find.get(s).equals(code = new Scanner(System.in).next()))) {
                            System.out.println("密码错误，请重新输入密码");
                        }
                        manager.setPassword(code);
                        System.out.println("正在登入\n=================");
                        Thread.sleep(2000);
                        return;
                    }
                }
            }
            System.out.println("无效账号，请重新登录");
            System.out.println("账号");
            manager.setUsename(new Scanner(System.in).next());
            System.out.println("密码");
            manager.setPassword(new Scanner(System.in).next());
        }
    }

    public void Logon(Manager manager) throws Exception{
        prop.setProperty(manager.getUsename(),manager.getPassword());
        FileWriter fw = new FileWriter("C:\\Users\\啦啦啦\\Desktop\\Manager.txt",true);
        prop.store(fw,"新管理员");
        System.out.println("正在注册\n=================");
        Thread.sleep(2000);
        System.out.println("注册成功");
    }
}
